package com.wangshupo.app.geekpark.control;

import com.wangshupo.app.geekpark.model.Author;
import com.wangshupo.app.geekpark.service.AuthorService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/author/api")
public class AuthorTest {

    @Autowired
    private AuthorService authorService;

    @GetMapping("/test")
    public  Map testAuthor(){
        Map resultData = new HashMap<>();  //存储结果

        Author author = new Author();
        author.setName("汪书坡");
        author.setNick("wangshupo");

        Author author1 = authorService.addAuthor(author); //添加一个用户(自动填充一个主键值)
        resultData.put("author1",author1);

        Author author2 = authorService.getAuthorById(author1.getId()); //查询用户
        resultData.put("author2",author2);


        Author authorModify = new Author();
        authorModify.setId(author1.getId());  //设置要修改的Author的ID主键
        authorModify.setName("西瓜真甜");
        authorModify.setNick("tiantianyaya");

        boolean tag1 = authorService.modify(authorModify);  //修改用户
        resultData.put("是否修改成功",tag1);

        Author author3 = authorService.getAuthorById(author1.getId()); //查询用户
        resultData.put("修改后的用户",author3);


        boolean tag2 = authorService.delete(author1.getId());
        resultData.put("是否删除成功",tag2);

        Author authorDetele = authorService.getAuthorById( author1.getId() );
        resultData.put("authorDetele",authorDetele);



        return resultData;
    }

}
